home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WUNZ20SR.ZIP / WNDPROC.C < prev   
C/C++ Source or Header  |  1993-07-12  |  42KB  |  1,025 lines

  1. #include <sys\types.h>
  2. #include <sys\stat.h>
  3. #include <time.h>                
  4. #include <string.h>             
  5. #include "wizunzip.h"
  6. #include "helpids.h"
  7. #include <shellapi.h>
  8.  
  9.  
  10. /* Windows Info-ZIP Unzip Window Procedure, wndproc.c.
  11.  * Author: Robert A. Heath, 157 Chartwell Rd., Columbia, SC 29210
  12.  * I, Robert Heath, place this source code module in the public domain.
  13.  */
  14.  
  15. #define MAKE_TABSTOP_TABLE_ENTRY(WNDHANDLE, ID) \
  16.     { \
  17.         TabStopTable[ID - TABSTOP_ID_BASE].lpfnOldFunc = \
  18.             (FARPROC)GetWindowLong(WNDHANDLE, GWL_WNDPROC); \
  19.         SetWindowLong(WNDHANDLE, GWL_WNDPROC, (LONG)lpfnKbd); \
  20.         TabStopTable[ID - TABSTOP_ID_BASE].hWnd = WNDHANDLE; \
  21.     }
  22.  
  23. /* Forward Refs
  24.  */
  25. static void GetArchiveDir(LPSTR lpszDestDir);
  26.  
  27. HWND hPatternSelectDlg; /* pattern select modeless dialog    */
  28. static UINT uCommDlgHelpMsg;    /* common dialog help message ID */
  29. static DWORD dwCommDlgHelpId = HELPID_HELP; /* what to pass to WinHelp() */
  30.  
  31. static char szFormatKeyword[2][6] = { "short", "long" };
  32.  
  33. /* Trailers are the lines just above the totals */
  34. static char * __based(__segname("STRINGS_TEXT")) szTrailers[2] = {
  35. " ------                    -------",
  36. " ------          ------  ---                              -------"
  37. } ;
  38.  
  39. static char __based(__segname("STRINGS_TEXT")) szCantChDir[] = 
  40.     "Internal error: Cannot change directory. Common dialog error code is 0x%lX.";
  41.  
  42. /* size of char in SYSTEM font in pixels */
  43. short dxChar, dyChar;
  44.  
  45. /* button control table -- one entry for 
  46.  * each of 4 entries. Indexed by the window ID relative to
  47.  * the first tabstop (TABSTOP_ID_BASE).         
  48.  */
  49. TabStopEntry TabStopTable[TABSTOP_TABLE_ENTRIES]; 
  50.  
  51.  
  52. static LPSTR
  53. lstrrchr(LPSTR lpszSrc, char chFind)
  54. {
  55.     LPSTR   lpszFound = (LPSTR)0;
  56.     LPSTR   lpszT;
  57.     
  58.     if ( lpszSrc )
  59.     {
  60.         for (lpszT = lpszSrc; *lpszT; ++lpszT)
  61.         {
  62.             if ((*lpszT) == chFind)
  63.                 lpszFound = lpszT;
  64.         }
  65.     }
  66.     
  67.     return lpszFound;
  68. }
  69.  
  70. /* Copy only the path portion of current file name into
  71.  * given buffer, lpszDestDir, translate into ANSI.
  72.  */
  73. static void GetArchiveDir(LPSTR lpszDestDir)
  74. {
  75. LPSTR lpchLast;
  76.  
  77.     /* strip off filename to make directory name    */
  78.     OemToAnsi(lpumb->szFileName, lpszDestDir);
  79.     if (lpchLast = lstrrchr(lpszDestDir, '\\'))
  80.         *lpchLast = '\0';
  81.  
  82.     else if (lpchLast = lstrrchr(lpszDestDir, ':'))
  83.         *(++lpchLast) = '\0'; /* clobber char AFTER the colon! */
  84.  
  85. }
  86.  
  87.  
  88. /****************************************************************************
  89.  
  90.     FUNCTION: SetCaption(HWND hWnd)
  91.                 
  92.  
  93.     PURPOSE: Set new caption for main window
  94.  
  95. ****************************************************************************/
  96. void 
  97. SetCaption(HWND hWnd)
  98. {
  99. #define SIMPLE_NAME_LEN 15
  100.  
  101.     WORD wMenuState;
  102.     char szSimpleFileName[SIMPLE_NAME_LEN+1];  /* just the 8.3 part in ANSI char set */
  103.     LPSTR lpszFileNameT;        /* pointer to simple filename               */
  104.     BOOL    fIconic = IsIconic(hWnd);   /* is window iconic ?   */
  105.  
  106.     /* point to simple filename in OEM char set                 */
  107.     if ((lpszFileNameT = lstrrchr(lpumb->szFileName, '\\')) ||
  108.         (lpszFileNameT = lstrrchr(lpumb->szFileName, ':')))
  109.         lpszFileNameT++;
  110.     else
  111.         lpszFileNameT = lpumb->szFileName;
  112.  
  113.     _fstrncpy(szSimpleFileName, lpszFileNameT, SIMPLE_NAME_LEN);
  114.     szSimpleFileName[SIMPLE_NAME_LEN] = '\0'; /* force termination */
  115.     OemToAnsi(szSimpleFileName, szSimpleFileName);
  116.     (void)wsprintf(lpumb->szBuffer, "%s - %s %s %s", 
  117.                     (LPSTR)szAppName, 
  118.                     (LPSTR)(szSimpleFileName[0] ? 
  119.                         szSimpleFileName : "(No .ZIP file)"),
  120.                     (LPSTR)(!fIconic && lpumb->szUnzipToDirName[0] ? " - " : ""),
  121.                     (LPSTR)(!fIconic ? lpumb->szUnzipToDirName : ""));
  122.     SetWindowText(hWnd, lpumb->szBuffer);
  123.     wMenuState = (WORD)(szSimpleFileName[0] ? MF_ENABLED : MF_GRAYED) ;
  124.     EnableMenuItem(hMenu, IDM_SELECT_ALL, wMenuState|MF_BYCOMMAND); 
  125.     EnableMenuItem(hMenu, IDM_DESELECT_ALL, wMenuState|MF_BYCOMMAND); 
  126.     EnableMenuItem(hMenu, IDM_SELECT_BY_PATTERN, wMenuState|MF_BYCOMMAND); 
  127. }
  128.  
  129. static void ManageStatusWnd(WORD wParam);
  130. static void ManageStatusWnd(WORD wParam)
  131. {
  132. int nWndState;  /* ShowWindow state     */
  133. BOOL fWndEnabled;   /* Enable Window state */
  134.  
  135.     if (wParam == IDM_SPLIT)
  136.     {
  137.          ShowWindow(hWndStatus, SW_RESTORE);
  138.          UpdateWindow(hWndStatus);
  139.          fWndEnabled = TRUE;
  140.          nWndState = SW_SHOWNORMAL;
  141.     }
  142.     else    /* Message window goes to maximum state     */
  143.     {
  144.          nWndState = SW_HIDE;    /* assume max state     */
  145.          fWndEnabled = FALSE;
  146.     }
  147.  
  148.     wWindowSelection = wParam; /* window selection: listbox, status, both    */
  149.     EnableWindow( hWndList, fWndEnabled);
  150.     UpdateWindow( hWndList);
  151.     ShowWindow( hWndList, nWndState);
  152.  
  153.     if (wParam == IDM_SPLIT) /* uncover buttons    */
  154.     {
  155.         UpdateButtons(hWndMain);    /* restore to proper state  */
  156.     }
  157.     else    /* else Message window occludes buttons         */
  158.     {
  159.         EnableWindow( hExtract, fWndEnabled);
  160.         EnableWindow( hTest, fWndEnabled);
  161.         EnableWindow( hDisplay, fWndEnabled);
  162.         EnableWindow( hShowComment, fWndEnabled);
  163.     }
  164.  
  165.     UpdateWindow( hExtract);
  166.     ShowWindow( hExtract, nWndState);
  167.  
  168.     ShowWindow( hTest, nWndState);
  169.     UpdateWindow( hTest);
  170.  
  171.     ShowWindow( hDisplay, nWndState);
  172.     UpdateWindow( hDisplay);
  173.  
  174.     ShowWindow( hShowComment, nWndState);
  175.     UpdateWindow( hShowComment);
  176.  
  177.     if (wParam == IDM_MAX_STATUS)   /* message box max'd out */
  178.     {
  179.         ShowWindow(hWndStatus, SW_SHOWMAXIMIZED);
  180.     }
  181.     SetFocus(hWndStatus);
  182.     SizeWindow(hWndMain, FALSE);
  183. }
  184.  
  185. /****************************************************************************
  186.  
  187.     FUNCTION: WizunzipWndProc(HWND, unsigned, WORD, LONG)
  188.  
  189.     PURPOSE:  Processes messages
  190.  
  191.     MESSAGES:
  192.  
  193.     WM_DESTROY      - destroy window
  194.     WM_SIZE         - window size has changed
  195.     WM_QUERYENDSESSION - willing to end session?
  196.     WM_ENDSESSION   - end Windows session
  197.     WM_CLOSE        - close the window
  198.     WM_SIZE         - window resized
  199.     WM_PAINT        - windows needs to be painted
  200.     WM_DROPFILES    - open a dropped file
  201.     COMMENTS:
  202.  
  203.     WM_COMMAND processing:
  204.  
  205.         IDM_OPEN -  open a new file.
  206.  
  207.  
  208.         IDM_EXIT - query to save current file if there is one and it
  209.                has been changed, then exit.
  210.  
  211.         IDM_ABOUT - display "About" box.
  212.  
  213. ****************************************************************************/
  214.  
  215. long FAR PASCAL WizunzipWndProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
  216. {
  217.     FARPROC lpfnAbout, lpfnSelectDir;
  218.  
  219.     HDC hDC;                /* device context       */
  220.     TEXTMETRIC    tm;           /* text metric structure    */
  221.     POINT point;
  222.     FARPROC lpfnKbd;
  223.     static int nCxBorder, nCyBorder;
  224.  
  225.  
  226.  
  227.     switch (wMessage)
  228.     {
  229.     case WM_CREATE: /* create  window       */
  230.         nCxBorder = GetSystemMetrics(SM_CXBORDER);
  231.         nCyBorder = GetSystemMetrics(SM_CYBORDER);
  232.         hInst = ((LPCREATESTRUCT)lParam)->hInstance;
  233.         lpfnKbd = MakeProcInstance((FARPROC)KbdProc, hInst);
  234.         hAccTable = LoadAccelerators(hInst, "WizunzipAccels");
  235.         hBrush = CreateSolidBrush(GetSysColor(BG_SYS_COLOR)); /* background */
  236.  
  237.         hMenu = GetMenu(hWnd);
  238.         /* Check Menu items to reflect WIN.INI settings */
  239.         CheckMenuItem(hMenu, IDM_RECR_DIR_STRUCT, MF_BYCOMMAND | 
  240.                             (uf.fRecreateDirs ? MF_CHECKED : MF_UNCHECKED));
  241.         CheckMenuItem(hMenu, (IDM_SHORT+uf.fFormatLong), MF_BYCOMMAND | MF_CHECKED);
  242.         CheckMenuItem(hMenu, IDM_OVERWRITE, MF_BYCOMMAND |
  243.                             (uf.fOverwrite ? MF_CHECKED : MF_UNCHECKED));
  244.         CheckMenuItem(hMenu, IDM_TRANSLATE, MF_BYCOMMAND |
  245.                             (uf.fTranslate ? MF_CHECKED : MF_UNCHECKED));
  246.         CheckMenuItem(hMenu, wLBSelection, MF_BYCOMMAND | MF_CHECKED